package com.caoji.item.web;

import com.caoji.entity.CategoryDto;
import com.caoji.item.entity.Category;
import com.caoji.item.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import sun.misc.Cache;

import java.util.List;

@RestController
@RequestMapping("category")
public class CategoryController {

    @Autowired
    private  CategoryService categoryService;

    //根据分类id，查询商品分类
   @GetMapping("/{id}")
    public ResponseEntity<CategoryDto> findbyid(@PathVariable("id")Long id){
       return  ResponseEntity.ok(categoryService.findbyid(id));
   }
   //根据分类id的集合，查询商品分类的集合
   @GetMapping("/list")
   public ResponseEntity<List<CategoryDto>> findbyids(@RequestParam("ids")List<Long> ids){
       return  ResponseEntity.ok(categoryService.findbyids(ids));
   }

    //根据品牌id，查询商品分类的集合
    @GetMapping("/of/brand")
    public ResponseEntity<List<CategoryDto>> findselectid(@RequestParam("id")Long id){
        return  ResponseEntity.ok(categoryService.findbybandis(id));
    }

    //根据父类目id，查询子类目的集合
    @GetMapping("/of/parent")
    public ResponseEntity<List<CategoryDto>> findbyparent(@RequestParam("pid")Long  pid){
        return  ResponseEntity.ok(categoryService.findbyparent(pid));
    }
}
